package org.germinus.telcoblocks.servicios.diagram.part;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.gmf.runtime.notation.View;
import org.germinus.telcoblocks.Anuncios;
import org.germinus.telcoblocks.ClickToDial;
import org.germinus.telcoblocks.Desvio;
import org.germinus.telcoblocks.Enlace;
import org.germinus.telcoblocks.Facturacion;
import org.germinus.telcoblocks.Llamadas;
import org.germinus.telcoblocks.Nodo;
import org.germinus.telcoblocks.NodoSERVICIOS;
import org.germinus.telcoblocks.Personalizacion;
import org.germinus.telcoblocks.ServicioGen;
import org.germinus.telcoblocks.TelcoblocksPackage;
import org.germinus.telcoblocks.Telefono;
import org.germinus.telcoblocks.Web;
import org.germinus.telcoblocks.servicios.diagram.edit.parts.AnunciosEditPart;
import org.germinus.telcoblocks.servicios.diagram.edit.parts.ClickToDialEditPart;
import org.germinus.telcoblocks.servicios.diagram.edit.parts.DesvioEditPart;
import org.germinus.telcoblocks.servicios.diagram.edit.parts.EnlaceEditPart;
import org.germinus.telcoblocks.servicios.diagram.edit.parts.FacturacionEditPart;
import org.germinus.telcoblocks.servicios.diagram.edit.parts.IMEditPart;
import org.germinus.telcoblocks.servicios.diagram.edit.parts.LlamadasEditPart;
import org.germinus.telcoblocks.servicios.diagram.edit.parts.PersonalizacionEditPart;
import org.germinus.telcoblocks.servicios.diagram.edit.parts.SERVICIOSEditPart;
import org.germinus.telcoblocks.servicios.diagram.edit.parts.ServicioGenEditPart;
import org.germinus.telcoblocks.servicios.diagram.edit.parts.TelefonoEditPart;
import org.germinus.telcoblocks.servicios.diagram.edit.parts.WebEditPart;
import org.germinus.telcoblocks.servicios.diagram.providers.TelcoblocksElementTypes;

/**
 * @generated
 */
public class TelcoblocksDiagramUpdater {

	/**
	 * @generated
	 */
	public static List getSemanticChildren(View view) {
		switch (TelcoblocksVisualIDRegistry.getVisualID(view)) {
		case SERVICIOSEditPart.VISUAL_ID:
			return getSERVICIOS_1000SemanticChildren(view);
		}
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getSERVICIOS_1000SemanticChildren(View view) {
		if (!view.isSetElement()) {
			return Collections.EMPTY_LIST;
		}
		org.germinus.telcoblocks.SERVICIOS modelElement = (org.germinus.telcoblocks.SERVICIOS) view
				.getElement();
		List result = new LinkedList();
		for (Iterator it = modelElement.getNodos().iterator(); it.hasNext();) {
			NodoSERVICIOS childElement = (NodoSERVICIOS) it.next();
			int visualID = TelcoblocksVisualIDRegistry.getNodeVisualID(view,
					childElement);
			if (visualID == ClickToDialEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
				continue;
			}
			if (visualID == LlamadasEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
				continue;
			}
			if (visualID == ServicioGenEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
				continue;
			}
			if (visualID == PersonalizacionEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
				continue;
			}
			if (visualID == IMEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
				continue;
			}
			if (visualID == FacturacionEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
				continue;
			}
			if (visualID == WebEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
				continue;
			}
			if (visualID == DesvioEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
				continue;
			}
			if (visualID == AnunciosEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
				continue;
			}
			if (visualID == TelefonoEditPart.VISUAL_ID) {
				result
						.add(new TelcoblocksNodeDescriptor(childElement,
								visualID));
				continue;
			}
		}
		return result;
	}

	/**
	 * @generated
	 */
	public static List getContainedLinks(View view) {
		switch (TelcoblocksVisualIDRegistry.getVisualID(view)) {
		case SERVICIOSEditPart.VISUAL_ID:
			return getSERVICIOS_1000ContainedLinks(view);
		case ClickToDialEditPart.VISUAL_ID:
			return getClickToDial_2001ContainedLinks(view);
		case LlamadasEditPart.VISUAL_ID:
			return getLlamadas_2002ContainedLinks(view);
		case ServicioGenEditPart.VISUAL_ID:
			return getServicioGen_2003ContainedLinks(view);
		case PersonalizacionEditPart.VISUAL_ID:
			return getPersonalizacion_2004ContainedLinks(view);
		case IMEditPart.VISUAL_ID:
			return getIM_2005ContainedLinks(view);
		case FacturacionEditPart.VISUAL_ID:
			return getFacturacion_2006ContainedLinks(view);
		case WebEditPart.VISUAL_ID:
			return getWeb_2007ContainedLinks(view);
		case DesvioEditPart.VISUAL_ID:
			return getDesvio_2008ContainedLinks(view);
		case AnunciosEditPart.VISUAL_ID:
			return getAnuncios_2009ContainedLinks(view);
		case TelefonoEditPart.VISUAL_ID:
			return getTelefono_2010ContainedLinks(view);
		case EnlaceEditPart.VISUAL_ID:
			return getEnlace_4001ContainedLinks(view);
		}
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getIncomingLinks(View view) {
		switch (TelcoblocksVisualIDRegistry.getVisualID(view)) {
		case ClickToDialEditPart.VISUAL_ID:
			return getClickToDial_2001IncomingLinks(view);
		case LlamadasEditPart.VISUAL_ID:
			return getLlamadas_2002IncomingLinks(view);
		case ServicioGenEditPart.VISUAL_ID:
			return getServicioGen_2003IncomingLinks(view);
		case PersonalizacionEditPart.VISUAL_ID:
			return getPersonalizacion_2004IncomingLinks(view);
		case IMEditPart.VISUAL_ID:
			return getIM_2005IncomingLinks(view);
		case FacturacionEditPart.VISUAL_ID:
			return getFacturacion_2006IncomingLinks(view);
		case WebEditPart.VISUAL_ID:
			return getWeb_2007IncomingLinks(view);
		case DesvioEditPart.VISUAL_ID:
			return getDesvio_2008IncomingLinks(view);
		case AnunciosEditPart.VISUAL_ID:
			return getAnuncios_2009IncomingLinks(view);
		case TelefonoEditPart.VISUAL_ID:
			return getTelefono_2010IncomingLinks(view);
		case EnlaceEditPart.VISUAL_ID:
			return getEnlace_4001IncomingLinks(view);
		}
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getOutgoingLinks(View view) {
		switch (TelcoblocksVisualIDRegistry.getVisualID(view)) {
		case ClickToDialEditPart.VISUAL_ID:
			return getClickToDial_2001OutgoingLinks(view);
		case LlamadasEditPart.VISUAL_ID:
			return getLlamadas_2002OutgoingLinks(view);
		case ServicioGenEditPart.VISUAL_ID:
			return getServicioGen_2003OutgoingLinks(view);
		case PersonalizacionEditPart.VISUAL_ID:
			return getPersonalizacion_2004OutgoingLinks(view);
		case IMEditPart.VISUAL_ID:
			return getIM_2005OutgoingLinks(view);
		case FacturacionEditPart.VISUAL_ID:
			return getFacturacion_2006OutgoingLinks(view);
		case WebEditPart.VISUAL_ID:
			return getWeb_2007OutgoingLinks(view);
		case DesvioEditPart.VISUAL_ID:
			return getDesvio_2008OutgoingLinks(view);
		case AnunciosEditPart.VISUAL_ID:
			return getAnuncios_2009OutgoingLinks(view);
		case TelefonoEditPart.VISUAL_ID:
			return getTelefono_2010OutgoingLinks(view);
		case EnlaceEditPart.VISUAL_ID:
			return getEnlace_4001OutgoingLinks(view);
		}
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getSERVICIOS_1000ContainedLinks(View view) {
		org.germinus.telcoblocks.SERVICIOS modelElement = (org.germinus.telcoblocks.SERVICIOS) view
				.getElement();
		List result = new LinkedList();
		result
				.addAll(getContainedTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getClickToDial_2001ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getLlamadas_2002ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getServicioGen_2003ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getPersonalizacion_2004ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getIM_2005ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getFacturacion_2006ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getWeb_2007ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getDesvio_2008ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getAnuncios_2009ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getTelefono_2010ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getEnlace_4001ContainedLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getClickToDial_2001IncomingLinks(View view) {
		ClickToDial modelElement = (ClickToDial) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getLlamadas_2002IncomingLinks(View view) {
		Llamadas modelElement = (Llamadas) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getServicioGen_2003IncomingLinks(View view) {
		ServicioGen modelElement = (ServicioGen) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getPersonalizacion_2004IncomingLinks(View view) {
		Personalizacion modelElement = (Personalizacion) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getIM_2005IncomingLinks(View view) {
		org.germinus.telcoblocks.IM modelElement = (org.germinus.telcoblocks.IM) view
				.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getFacturacion_2006IncomingLinks(View view) {
		Facturacion modelElement = (Facturacion) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getWeb_2007IncomingLinks(View view) {
		Web modelElement = (Web) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getDesvio_2008IncomingLinks(View view) {
		Desvio modelElement = (Desvio) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getAnuncios_2009IncomingLinks(View view) {
		Anuncios modelElement = (Anuncios) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getTelefono_2010IncomingLinks(View view) {
		Telefono modelElement = (Telefono) view.getElement();
		Map crossReferences = EcoreUtil.CrossReferencer.find(view.eResource()
				.getResourceSet().getResources());
		List result = new LinkedList();
		result.addAll(getIncomingTypeModelFacetLinks_Enlace_4001(modelElement,
				crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getEnlace_4001IncomingLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	public static List getClickToDial_2001OutgoingLinks(View view) {
		ClickToDial modelElement = (ClickToDial) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getLlamadas_2002OutgoingLinks(View view) {
		Llamadas modelElement = (Llamadas) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getServicioGen_2003OutgoingLinks(View view) {
		ServicioGen modelElement = (ServicioGen) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getPersonalizacion_2004OutgoingLinks(View view) {
		Personalizacion modelElement = (Personalizacion) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getIM_2005OutgoingLinks(View view) {
		org.germinus.telcoblocks.IM modelElement = (org.germinus.telcoblocks.IM) view
				.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getFacturacion_2006OutgoingLinks(View view) {
		Facturacion modelElement = (Facturacion) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getWeb_2007OutgoingLinks(View view) {
		Web modelElement = (Web) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getDesvio_2008OutgoingLinks(View view) {
		Desvio modelElement = (Desvio) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getAnuncios_2009OutgoingLinks(View view) {
		Anuncios modelElement = (Anuncios) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getTelefono_2010OutgoingLinks(View view) {
		Telefono modelElement = (Telefono) view.getElement();
		List result = new LinkedList();
		result.addAll(getOutgoingTypeModelFacetLinks_Enlace_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List getEnlace_4001OutgoingLinks(View view) {
		return Collections.EMPTY_LIST;
	}

	/**
	 * @generated
	 */
	private static Collection getContainedTypeModelFacetLinks_Enlace_4001(
			org.germinus.telcoblocks.SERVICIOS container) {
		Collection result = new LinkedList();
		for (Iterator links = container.getEnlaces().iterator(); links
				.hasNext();) {
			EObject linkObject = (EObject) links.next();
			if (false == linkObject instanceof Enlace) {
				continue;
			}
			Enlace link = (Enlace) linkObject;
			if (EnlaceEditPart.VISUAL_ID != TelcoblocksVisualIDRegistry
					.getLinkWithClassVisualID(link)) {
				continue;
			}
			Nodo dst = link.getDestino();
			Nodo src = link.getOrigen();
			result.add(new TelcoblocksLinkDescriptor(src, dst, link,
					TelcoblocksElementTypes.Enlace_4001,
					EnlaceEditPart.VISUAL_ID));
		}
		return result;
	}

	/**
	 * @generated
	 */
	private static Collection getIncomingTypeModelFacetLinks_Enlace_4001(
			Nodo target, Map crossReferences) {
		Collection result = new LinkedList();
		Collection settings = (Collection) crossReferences.get(target);
		for (Iterator it = settings.iterator(); it.hasNext();) {
			EStructuralFeature.Setting setting = (EStructuralFeature.Setting) it
					.next();
			if (setting.getEStructuralFeature() != TelcoblocksPackage.eINSTANCE
					.getEnlace_Destino()
					|| false == setting.getEObject() instanceof Enlace) {
				continue;
			}
			Enlace link = (Enlace) setting.getEObject();
			if (EnlaceEditPart.VISUAL_ID != TelcoblocksVisualIDRegistry
					.getLinkWithClassVisualID(link)) {
				continue;
			}
			Nodo src = link.getOrigen();
			result.add(new TelcoblocksLinkDescriptor(src, target, link,
					TelcoblocksElementTypes.Enlace_4001,
					EnlaceEditPart.VISUAL_ID));
		}
		return result;
	}

	/**
	 * @generated
	 */
	private static Collection getOutgoingTypeModelFacetLinks_Enlace_4001(
			Nodo source) {
		org.germinus.telcoblocks.SERVICIOS container = null;
		// Find container element for the link.
		// Climb up by containment hierarchy starting from the source
		// and return the first element that is instance of the container class.
		for (EObject element = source; element != null && container == null; element = element
				.eContainer()) {
			if (element instanceof org.germinus.telcoblocks.SERVICIOS) {
				container = (org.germinus.telcoblocks.SERVICIOS) element;
			}
		}
		if (container == null) {
			return Collections.EMPTY_LIST;
		}
		Collection result = new LinkedList();
		for (Iterator links = container.getEnlaces().iterator(); links
				.hasNext();) {
			EObject linkObject = (EObject) links.next();
			if (false == linkObject instanceof Enlace) {
				continue;
			}
			Enlace link = (Enlace) linkObject;
			if (EnlaceEditPart.VISUAL_ID != TelcoblocksVisualIDRegistry
					.getLinkWithClassVisualID(link)) {
				continue;
			}
			Nodo dst = link.getDestino();
			Nodo src = link.getOrigen();
			if (src != source) {
				continue;
			}
			result.add(new TelcoblocksLinkDescriptor(src, dst, link,
					TelcoblocksElementTypes.Enlace_4001,
					EnlaceEditPart.VISUAL_ID));
		}
		return result;
	}

}
